// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class WeightedAverageAggregation
{
	/// <summary>
	/// <para>A numeric response formatter.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("format")]
	public string? Format { get; set; }

	/// <summary>
	/// <para>Configuration for the field that provides the values.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("value")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? Value { get; set; }
	[JsonInclude, JsonPropertyName("value_type")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.ValueType? ValueType { get; set; }

	/// <summary>
	/// <para>Configuration for the field or script that provides the weights.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("weight")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? Weight { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation(WeightedAverageAggregation weightedAverageAggregation) => Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation.WeightedAvg(weightedAverageAggregation);
}

public sealed partial class WeightedAverageAggregationDescriptor<TDocument> : SerializableDescriptor<WeightedAverageAggregationDescriptor<TDocument>>
{
	internal WeightedAverageAggregationDescriptor(Action<WeightedAverageAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public WeightedAverageAggregationDescriptor() : base()
	{
	}

	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? ValueValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument> ValueDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument>> ValueDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ValueType? ValueTypeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? WeightValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument> WeightDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument>> WeightDescriptorAction { get; set; }

	/// <summary>
	/// <para>A numeric response formatter.</para>
	/// </summary>
	public WeightedAverageAggregationDescriptor<TDocument> Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	/// <summary>
	/// <para>Configuration for the field that provides the values.</para>
	/// </summary>
	public WeightedAverageAggregationDescriptor<TDocument> Value(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? value)
	{
		ValueDescriptor = null;
		ValueDescriptorAction = null;
		ValueValue = value;
		return Self;
	}

	public WeightedAverageAggregationDescriptor<TDocument> Value(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument> descriptor)
	{
		ValueValue = null;
		ValueDescriptorAction = null;
		ValueDescriptor = descriptor;
		return Self;
	}

	public WeightedAverageAggregationDescriptor<TDocument> Value(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument>> configure)
	{
		ValueValue = null;
		ValueDescriptor = null;
		ValueDescriptorAction = configure;
		return Self;
	}

	public WeightedAverageAggregationDescriptor<TDocument> ValueType(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ValueType? valueType)
	{
		ValueTypeValue = valueType;
		return Self;
	}

	/// <summary>
	/// <para>Configuration for the field or script that provides the weights.</para>
	/// </summary>
	public WeightedAverageAggregationDescriptor<TDocument> Weight(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? weight)
	{
		WeightDescriptor = null;
		WeightDescriptorAction = null;
		WeightValue = weight;
		return Self;
	}

	public WeightedAverageAggregationDescriptor<TDocument> Weight(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument> descriptor)
	{
		WeightValue = null;
		WeightDescriptorAction = null;
		WeightDescriptor = descriptor;
		return Self;
	}

	public WeightedAverageAggregationDescriptor<TDocument> Weight(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument>> configure)
	{
		WeightValue = null;
		WeightDescriptor = null;
		WeightDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (ValueDescriptor is not null)
		{
			writer.WritePropertyName("value");
			JsonSerializer.Serialize(writer, ValueDescriptor, options);
		}
		else if (ValueDescriptorAction is not null)
		{
			writer.WritePropertyName("value");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument>(ValueDescriptorAction), options);
		}
		else if (ValueValue is not null)
		{
			writer.WritePropertyName("value");
			JsonSerializer.Serialize(writer, ValueValue, options);
		}

		if (ValueTypeValue is not null)
		{
			writer.WritePropertyName("value_type");
			JsonSerializer.Serialize(writer, ValueTypeValue, options);
		}

		if (WeightDescriptor is not null)
		{
			writer.WritePropertyName("weight");
			JsonSerializer.Serialize(writer, WeightDescriptor, options);
		}
		else if (WeightDescriptorAction is not null)
		{
			writer.WritePropertyName("weight");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor<TDocument>(WeightDescriptorAction), options);
		}
		else if (WeightValue is not null)
		{
			writer.WritePropertyName("weight");
			JsonSerializer.Serialize(writer, WeightValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class WeightedAverageAggregationDescriptor : SerializableDescriptor<WeightedAverageAggregationDescriptor>
{
	internal WeightedAverageAggregationDescriptor(Action<WeightedAverageAggregationDescriptor> configure) => configure.Invoke(this);

	public WeightedAverageAggregationDescriptor() : base()
	{
	}

	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? ValueValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor ValueDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor> ValueDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ValueType? ValueTypeValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? WeightValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor WeightDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor> WeightDescriptorAction { get; set; }

	/// <summary>
	/// <para>A numeric response formatter.</para>
	/// </summary>
	public WeightedAverageAggregationDescriptor Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	/// <summary>
	/// <para>Configuration for the field that provides the values.</para>
	/// </summary>
	public WeightedAverageAggregationDescriptor Value(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? value)
	{
		ValueDescriptor = null;
		ValueDescriptorAction = null;
		ValueValue = value;
		return Self;
	}

	public WeightedAverageAggregationDescriptor Value(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor descriptor)
	{
		ValueValue = null;
		ValueDescriptorAction = null;
		ValueDescriptor = descriptor;
		return Self;
	}

	public WeightedAverageAggregationDescriptor Value(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor> configure)
	{
		ValueValue = null;
		ValueDescriptor = null;
		ValueDescriptorAction = configure;
		return Self;
	}

	public WeightedAverageAggregationDescriptor ValueType(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ValueType? valueType)
	{
		ValueTypeValue = valueType;
		return Self;
	}

	/// <summary>
	/// <para>Configuration for the field or script that provides the weights.</para>
	/// </summary>
	public WeightedAverageAggregationDescriptor Weight(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValue? weight)
	{
		WeightDescriptor = null;
		WeightDescriptorAction = null;
		WeightValue = weight;
		return Self;
	}

	public WeightedAverageAggregationDescriptor Weight(Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor descriptor)
	{
		WeightValue = null;
		WeightDescriptorAction = null;
		WeightDescriptor = descriptor;
		return Self;
	}

	public WeightedAverageAggregationDescriptor Weight(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor> configure)
	{
		WeightValue = null;
		WeightDescriptor = null;
		WeightDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (ValueDescriptor is not null)
		{
			writer.WritePropertyName("value");
			JsonSerializer.Serialize(writer, ValueDescriptor, options);
		}
		else if (ValueDescriptorAction is not null)
		{
			writer.WritePropertyName("value");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor(ValueDescriptorAction), options);
		}
		else if (ValueValue is not null)
		{
			writer.WritePropertyName("value");
			JsonSerializer.Serialize(writer, ValueValue, options);
		}

		if (ValueTypeValue is not null)
		{
			writer.WritePropertyName("value_type");
			JsonSerializer.Serialize(writer, ValueTypeValue, options);
		}

		if (WeightDescriptor is not null)
		{
			writer.WritePropertyName("weight");
			JsonSerializer.Serialize(writer, WeightDescriptor, options);
		}
		else if (WeightDescriptorAction is not null)
		{
			writer.WritePropertyName("weight");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.WeightedAverageValueDescriptor(WeightDescriptorAction), options);
		}
		else if (WeightValue is not null)
		{
			writer.WritePropertyName("weight");
			JsonSerializer.Serialize(writer, WeightValue, options);
		}

		writer.WriteEndObject();
	}
}